package header

import (
	"fmt"
	"strings"
	"udp_tcp_client/sip/header/common"
	"udp_tcp_client/util"
)

// Example：SIP/2.0/UDP 127.0.0.1:15061;branch=z9hG4bK6b206a30cd;rport
type Via struct {
	SIPVersion string      // SIP版本号
	Transport  string      // 协议
	Client     string      // 客户端地址
	Arguments  common.Args // 参数列表
}

func NewVia(domain string, network string, args common.Args) (Via, error) {
	via := Via{}
	via.SIPVersion = util.SIPVersion
	via.Transport = strings.ToUpper(network)
	via.Client = domain
	via.Arguments = args
	return via, nil
}

func (v *Via) String() string {
	return fmt.Sprintf("%s/%s %s%s", v.SIPVersion, v.Transport, v.Client, v.Arguments.String())
}
